package com.fywsy.fyweb.controller;

import com.fywsy.fyweb.entity.*;
import com.fywsy.fyweb.service.AdminServie;
import com.fywsy.fyweb.utils.TextUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    AdminServie adminServie;

    @PostMapping("/saveGame")
    public String saveGame(@RequestBody RequestSaveGame request) {
        if (TextUtils.isEmpty(request.game.name) ||
            TextUtils.isEmpty(request.game.icon))
            return "缺少必要参数";

        return adminServie.saveGame(request);

    }


    @PostMapping("/gameList")
    public List<Game> gameList() {
        return adminServie.getGames();
    }


    @PostMapping("/gameDetail")
    public RequestSaveGame gameDetail(Long gameId) {
        return adminServie.getGameDetail(gameId);
    }

    @PostMapping("/updateGame")
    public ResponseEntity updateGame(@RequestBody Game game) {
        return adminServie.updateGame(game);
    }

    /**
     * 通过游戏id和关键词获取对应道具及全部功能，
     * 用于管理后台道具编辑
     *
     * @param gameId
     * @param keyword
     * @return
     */
    @GetMapping("/getItemsByGameId")
    public ResponseAdminItems getItemsByGameId(Long gameId, String keyword) {
        return adminServie.getItemsByGameId(gameId, keyword);
    }

    @PostMapping("/updateItem")
    public ResponseEntity updateItem(@RequestBody Item item) {
        return adminServie.updateItem(item);
    }
}
